package com.asa.gametheory;

import java.util.ArrayList;
import java.util.List;

public class GameUtils {

	
	/**
	 * 剔除绝对劣势策略
	 * 现在还只支持两个策略人的
	 * @param player
	 */
	public static void remove_Strategy(Player player) {

		double[][] pan = player.getPan();
		int n = player.getN();
		int ceng = player.getCeng();

		List<Integer> add = new ArrayList<Integer>();

		if (ceng == 0) {
			for (int i = 0; i < pan.length; i++) {
				List<Integer> maxlist = new ArrayList<Integer>();
				int max = 0;
				double maxitem = 0;
				for (int j = 0; j < pan[i].length; j++) {
					if (j == 0) {
						maxitem = pan[i][j];
						maxlist.add(j);
						continue;
					}

					if (maxitem < pan[i][j]) {
						max = j;
						maxitem = pan[i][j];
						maxlist.clear();
						maxlist.add(j);
					} else if (maxitem == pan[i][j]) {
						maxlist.add(j);
					}
				}
				add.addAll(maxlist);
			}
		} else if (ceng == 1){//这种旋转方式其实有一点点取巧，耍滑头，到三维的话要怎么做，我不知道，两个玩家暂时是够了，这样安慰自己吧
			double[][] pan2 = new double[pan[0].length][pan.length];
			for (int i = 0; i < pan2.length; i++) {
				for (int j = 0; j < pan2[i].length; j++) {
					pan2[i][j] = pan[j][i];
				}
			}

			pan = pan2;

			for (int i = 0; i < pan.length; i++) {
				List<Integer> maxlist = new ArrayList<Integer>();
				int max = 0;
				double maxitem = 0;
				for (int j = 0; j < pan[i].length; j++) {
					if (j == 0) {
						maxitem = pan[i][j];
						maxlist.add(j);
						continue;
					}

					if (maxitem < pan[i][j]) {
						max = j;
						maxitem = pan[i][j];
						maxlist.clear();
						maxlist.add(j);
					} else if (maxitem == pan[i][j]) {
						maxlist.add(j);
					}
				}
				add.addAll(maxlist);
			}
		}

		
		List<Integer> result = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			result.add(i);
		}
		
		for (int i = 0; i < add.size(); i++) {
			Integer integer = add.get(i);
			boolean remove = result.remove(integer);
		}
		
		player.setRemove(result);

//		System.out.println(result.size());
//		for (int i = 0; i < result.size(); i++) {
//
//			System.out.println(result.get(i));
//
//		}

	}

	public static void panone(double[][] a) {

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.print(a[i][j] + "\t\t");
			}
			System.out.println();
		}

	}

	public static void pan(double[][] a, double[][] b) {

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.print(a[i][j] + "," + b[i][j] + "\t\t");
			}
			System.out.println();
		}

	}

}
